package com.xyongfeng.foodManagement.controller;


import com.xyongfeng.foodManagement.common.BaseResponse;
import com.xyongfeng.foodManagement.common.ErrorCode;
import com.xyongfeng.foodManagement.common.ResultUtils;
import com.xyongfeng.foodManagement.domain.AdminInfo;
import com.xyongfeng.foodManagement.domain.FoodOutInfo;
import com.xyongfeng.foodManagement.domain.group.AddGroup;
import com.xyongfeng.foodManagement.domain.group.EditGroup;
import com.xyongfeng.foodManagement.domain.group.NormalGroup;
import com.xyongfeng.foodManagement.service.AdminInfoService;
import com.xyongfeng.foodManagement.service.FoodOutInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 控制食品出库的接口
 *
 * @author xyongfeng
 */
@RestController
@RequestMapping("/foodOut")
@Slf4j
public class FoodOutController {

    @Autowired
    private FoodOutInfoService foodOutInfoService;
    @Autowired
    private AdminInfoService adminInfoService;

    @GetMapping
    public BaseResponse<List<FoodOutInfo>> selectAll() {
        return ResultUtils.success(foodOutInfoService.selectAll());
    }
    @RequiresPermissions("foodOut")
    @PostMapping
    public BaseResponse<FoodOutInfo> insert(@RequestBody @Validated({AddGroup.class, NormalGroup.class}) FoodOutInfo foodOutInfo,
                                            HttpServletRequest request) {

        foodOutInfoService.insert(foodOutInfo, request);

        return ResultUtils.success(foodOutInfo);
    }


}
